//
//  Operation_BaseUse_VC.m
//  DXC
//
//  Created by TOPTEAM on 2017/5/9.
//  Copyright © 2017年 TOPTEAM. All rights reserved.
//

#import "Operation_BaseUse_VC.h"
#import "KKOperation.h"

@interface Operation_BaseUse_VC ()

@end

@implementation Operation_BaseUse_VC

-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
    //    KKOperation *op = [[KKOperation alloc]init];
    //    KKOperation *op1 = [[KKOperation alloc]init];
    //    [op start];
    //    [op1 start];
    
    [self blockOperation];
    
    //    [self invocation];
    
    //    [self download];
    
}


-(void)blockOperation
{
    //1.封装操作
    NSBlockOperation *op = [NSBlockOperation blockOperationWithBlock:^{
        //在主线程
        NSLog(@"1------%@",[NSThread currentThread]);
        
    }];
    
    NSBlockOperation *op1 = [NSBlockOperation blockOperationWithBlock:^{
        NSLog(@"2------%@",[NSThread currentThread]);
    }];
    
    //2.追加操作
    //在子线程中执行
    [op1 addExecutionBlock:^{
        NSLog(@"3------%@",[NSThread currentThread]);
    }];
    [op1 addExecutionBlock:^{
        NSLog(@"4------%@",[NSThread currentThread]);
    }];
    
    [op1 addExecutionBlock:^{
        NSLog(@"5------%@",[NSThread currentThread]);
    }];
    
    
    //3.启动操作执行
    [op start];
    [op1 start];
    
}
-(void)invocation
{
    //    NSOperation *op = [[NSOperation alloc]init];
    
    /*
     第一个参数:目标对象
     第二个参数:选择器,要调用的方法
     第三个参数:方法要传递的参数
     */
    //    NSInvocationOperation *op  = [[NSInvocationOperation alloc]initWithTarget:self selector:@selector(download) object:nil];
    //
    //    //启动操作
    //    [op start];
    
    [self performSelector:@selector(download) withObject:nil];
}
-(void)download
{
    NSLog(@"---%s---%@",__func__,[NSThread currentThread]);
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor=[UIColor whiteColor];
    self.title=@"NSOperation基本使用";
    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
